{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "321de339",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181 6765 10946 17711 \n"
     ]
    }
   ],
   "source": [
    "def fib(n): \n",
    "    \"\"\"输出斐波那契数列\"\"\"\n",
    "    \"\"\"Print a Fibonacci series up to n.\"\"\"\n",
    "    a, b = 0, 1\n",
    "    while a < n:\n",
    "        print(a, end =' ')\n",
    "        a, b= b, a+b\n",
    "    print()\n",
    "\n",
    "fib(20000)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "5c098bc8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'tuple'>\n",
      "<class 'int'>\n"
     ]
    }
   ],
   "source": [
    "def a(x,y):\n",
    "    '''定义多返回值函数'''\n",
    "    return y,x;\n",
    "\n",
    "x=a(1,2);\n",
    "print(type(x))\n",
    "\n",
    "x,y=a(1,2);\n",
    "print(type(x))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b1432632",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "25\n",
      "25\n",
      "125\n"
     ]
    }
   ],
   "source": [
    "def pow(x, n=2):\n",
    "    r = 1;\n",
    "    while n > 0:\n",
    "        n -= 1\n",
    "        r *= x\n",
    "    return r\n",
    "\n",
    "print(pow(5))\n",
    "print(pow(5))\n",
    "print(pow(5,3))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "17d9ec04",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "None\n"
     ]
    }
   ],
   "source": [
    "def add(*int):\n",
    "    r = 0;\n",
    "    for x in int:\n",
    "        r += x\n",
    "    return r\n",
    "\n",
    "print(add(1,2,3,4))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "6026a6d5",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4, 6]\n",
      "[1, 2, 3, 4]\n"
     ]
    }
   ],
   "source": [
    "def a(list):\n",
    "    list.append(6)\n",
    "    print(list)\n",
    "\n",
    "list = [1,2,3,4]\n",
    "\n",
    "a(list[:])\n",
    "print(list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "ceffd650",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{'w': 1, 'wfe': 2}\n",
      "{'a': {'w': 22}}\n"
     ]
    }
   ],
   "source": [
    "def foo(**attrs):\n",
    "    print(attrs)\n",
    "\n",
    "foo( w = 1 ,wfe=2)\n",
    "foo( a = {\"w\":22})"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
